<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>SystemSharp: SetAlgorithms.cs Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">SystemSharp
   &#160;<span id="projectnumber">0.3</span>
   </div>
   <div id="projectbrief">A system-level modeling framework for designing real-time embedded systems</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_set_algorithms_8cs_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Properties</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Events</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">SetAlgorithms.cs</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_set_algorithms_8cs.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="keyword">using</span> System;</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="keyword">using</span> System.Collections.Generic;</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="keyword">using</span> System.Diagnostics;</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="keyword">using</span> System.Linq;</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">using</span> System.Text;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">using</span> SystemSharp.Collections.EmilStefanov;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="keyword">using</span> SystemSharp.TreeAlgorithms;</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;</div>
<div class="line"><a name="l00028"></a><span class="lineno"><a class="line" href="namespace_system_sharp_1_1_set_algorithms.html">   28</a></span>&#160;<span class="keyword">namespace </span>SystemSharp.SetAlgorithms</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;{</div>
<div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="interface_system_sharp_1_1_set_algorithms_1_1_i_set_adapter_3_01_t_01_4.html">   34</a></span>&#160;    <span class="keyword">public</span> <span class="keyword">interface </span>ISetAdapter&lt;T&gt;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    {</div>
<div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="interface_system_sharp_1_1_set_algorithms_1_1_i_set_adapter_3_01_t_01_4.html#a4c695405376a518d9d738fc67504a34b">   39</a></span>&#160;        IPropMap&lt;T, int&gt; Index { <span class="keyword">get</span>; }</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    }</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;</div>
<div class="line"><a name="l00046"></a><span class="lineno"><a class="line" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html">   46</a></span>&#160;    <span class="keyword">public</span> <span class="keyword">class </span>UnionFind&lt;T&gt;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    {</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        <span class="keyword">private</span> IPropMap&lt;T, int&gt; _index;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        <span class="keyword">private</span> List&lt;T&gt; _elems;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        <span class="keyword">private</span> <a class="code" href="class_system_sharp_1_1_collections_1_1_emil_stefanov_1_1_disjoint_sets.html">DisjointSets</a> _impl;</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        <span class="keyword">private</span> <span class="keywordtype">int</span>[] _repShuffle; <span class="comment">// Used to pick the &quot;right&quot; representant for </span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;                                   <span class="comment">// Havlak&#39;s loop analysis</span></div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;</div>
<div class="line"><a name="l00060"></a><span class="lineno"><a class="line" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#acccd00bd7a1e361af0952d7b016bb80a">   60</a></span>&#160;        <span class="keyword">public</span> <a class="code" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#acccd00bd7a1e361af0952d7b016bb80a">UnionFind</a>(<a class="code" href="interface_system_sharp_1_1_set_algorithms_1_1_i_set_adapter_3_01_t_01_4.html">ISetAdapter&lt;T&gt;</a> a, IList&lt;T&gt; elems)</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        {</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;            _index = a.Index;</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;            _elems = <span class="keyword">new</span> List&lt;T&gt;(elems);</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;            _repShuffle = <span class="keyword">new</span> <span class="keywordtype">int</span>[elems.Count];</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; _elems.Count; i++)</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            {</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;                Debug.Assert(_index[_elems[i]] == i);</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;                _repShuffle[i] = i;</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;            }</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;            _impl = <span class="keyword">new</span> <a class="code" href="class_system_sharp_1_1_collections_1_1_emil_stefanov_1_1_disjoint_sets.html">DisjointSets</a>(elems.Count);</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;        }</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;</div>
<div class="line"><a name="l00078"></a><span class="lineno"><a class="line" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a4e0ae2e355bcc52807d9f929a200cb7f">   78</a></span>&#160;        <span class="keyword">public</span> T <a class="code" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a4e0ae2e355bcc52807d9f929a200cb7f">Find</a>(T elem)</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        {</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;            <span class="keywordtype">int</span> fidx = _impl.FindSet(_index[elem]);</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;            <span class="keywordflow">return</span> _elems[_repShuffle[fidx]];</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;        }</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div>
<div class="line"><a name="l00089"></a><span class="lineno"><a class="line" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a5b597afbe5030129f46d5d75a2bef97f">   89</a></span>&#160;        <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a5b597afbe5030129f46d5d75a2bef97f">Union</a>(T e1, T e2)</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;        {</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;            _impl.Union(_impl.FindSet(_index[e1]), _impl.FindSet(_index[e2]));</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;            _repShuffle[_impl.FindSet(_index[e2])] = _index[e2];</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        }</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;</div>
<div class="line"><a name="l00098"></a><span class="lineno"><a class="line" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a5d144a22537169cf6b085096c606e773">   98</a></span>&#160;        <span class="keyword">public</span> ILookup&lt;T, T&gt; <a class="code" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a5d144a22537169cf6b085096c606e773">ToLookup</a>()</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        {</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;            <span class="keywordflow">return</span> _elems.ToLookup(e =&gt; Find(e));</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;        }</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    }</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;</div>
<div class="line"><a name="l00104"></a><span class="lineno"><a class="line" href="class_system_sharp_1_1_set_algorithms_1_1_set_operations.html">  104</a></span>&#160;    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">class </span><a class="code" href="class_system_sharp_1_1_set_algorithms_1_1_set_operations.html">SetOperations</a></div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    {</div>
<div class="line"><a name="l00113"></a><span class="lineno"><a class="line" href="class_system_sharp_1_1_set_algorithms_1_1_set_operations.html#ad76f749f64542bf7170566fa2404257b">  113</a></span>&#160;        <span class="keyword">public</span> <span class="keyword">static</span> <a class="code" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html">UnionFind&lt;T&gt;</a> CreateUnionFind&lt;T&gt;(<span class="keyword">this</span> <a class="code" href="interface_system_sharp_1_1_set_algorithms_1_1_i_set_adapter_3_01_t_01_4.html">ISetAdapter&lt;T&gt;</a> a, IList&lt;T&gt; elems)</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;        {</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html">UnionFind&lt;T&gt;</a>(a, elems);</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;        }</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    }</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;}</div>
<div class="ttc" id="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4_html_a5d144a22537169cf6b085096c606e773"><div class="ttname"><a href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a5d144a22537169cf6b085096c606e773">SystemSharp.SetAlgorithms.UnionFind&lt; T &gt;.ToLookup</a></div><div class="ttdeci">ILookup&lt; T, T &gt; ToLookup()</div><div class="ttdoc">Represents this data structure as a lookup, providing the representant of each element. </div><div class="ttdef"><b>Definition:</b> <a href="_set_algorithms_8cs_source.html#l00098">SetAlgorithms.cs:98</a></div></div>
<div class="ttc" id="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4_html_a4e0ae2e355bcc52807d9f929a200cb7f"><div class="ttname"><a href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a4e0ae2e355bcc52807d9f929a200cb7f">SystemSharp.SetAlgorithms.UnionFind&lt; T &gt;.Find</a></div><div class="ttdeci">T Find(T elem)</div><div class="ttdoc">Finds the representant of a set element. </div><div class="ttdef"><b>Definition:</b> <a href="_set_algorithms_8cs_source.html#l00078">SetAlgorithms.cs:78</a></div></div>
<div class="ttc" id="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4_html_acccd00bd7a1e361af0952d7b016bb80a"><div class="ttname"><a href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#acccd00bd7a1e361af0952d7b016bb80a">SystemSharp.SetAlgorithms.UnionFind&lt; T &gt;.UnionFind</a></div><div class="ttdeci">UnionFind(ISetAdapter&lt; T &gt; a, IList&lt; T &gt; elems)</div><div class="ttdoc">Constructs an instance of the union-find data structure. </div><div class="ttdef"><b>Definition:</b> <a href="_set_algorithms_8cs_source.html#l00060">SetAlgorithms.cs:60</a></div></div>
<div class="ttc" id="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4_html_a5b597afbe5030129f46d5d75a2bef97f"><div class="ttname"><a href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html#a5b597afbe5030129f46d5d75a2bef97f">SystemSharp.SetAlgorithms.UnionFind&lt; T &gt;.Union</a></div><div class="ttdeci">void Union(T e1, T e2)</div><div class="ttdoc">Unifies two set elements. </div><div class="ttdef"><b>Definition:</b> <a href="_set_algorithms_8cs_source.html#l00089">SetAlgorithms.cs:89</a></div></div>
<div class="ttc" id="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4_html"><div class="ttname"><a href="class_system_sharp_1_1_set_algorithms_1_1_union_find_3_01_t_01_4.html">SystemSharp.SetAlgorithms.UnionFind&lt; T &gt;</a></div><div class="ttdoc">An implementation of the union-find data structure. </div><div class="ttdef"><b>Definition:</b> <a href="_set_algorithms_8cs_source.html#l00046">SetAlgorithms.cs:46</a></div></div>
<div class="ttc" id="interface_system_sharp_1_1_set_algorithms_1_1_i_set_adapter_3_01_t_01_4_html"><div class="ttname"><a href="interface_system_sharp_1_1_set_algorithms_1_1_i_set_adapter_3_01_t_01_4.html">SystemSharp.SetAlgorithms.ISetAdapter&lt; T &gt;</a></div><div class="ttdoc">Adapter interface for set algorithms. </div><div class="ttdef"><b>Definition:</b> <a href="_set_algorithms_8cs_source.html#l00034">SetAlgorithms.cs:34</a></div></div>
<div class="ttc" id="class_system_sharp_1_1_collections_1_1_emil_stefanov_1_1_disjoint_sets_html"><div class="ttname"><a href="class_system_sharp_1_1_collections_1_1_emil_stefanov_1_1_disjoint_sets.html">SystemSharp.Collections.EmilStefanov.DisjointSets</a></div><div class="ttdef"><b>Definition:</b> <a href="_disjoint_sets_8cs_source.html#l00031">DisjointSets.cs:31</a></div></div>
<div class="ttc" id="class_system_sharp_1_1_set_algorithms_1_1_set_operations_html"><div class="ttname"><a href="class_system_sharp_1_1_set_algorithms_1_1_set_operations.html">SystemSharp.SetAlgorithms.SetOperations</a></div><div class="ttdef"><b>Definition:</b> <a href="_set_algorithms_8cs_source.html#l00104">SetAlgorithms.cs:104</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_bb5e995590685548b7e11478911ee7c3.html">SystemSharp-Google-SVN</a></li><li class="navelem"><a class="el" href="dir_8deefa4467a62b572b52d238d562b104.html">SystemSharp</a></li><li class="navelem"><a class="el" href="dir_0e5a72156f8560bbc472a395da2569d6.html">SystemSharp</a></li><li class="navelem"><a class="el" href="dir_9d3c30b4336bd92c64ccf0aeee487ace.html">SystemSharp</a></li><li class="navelem"><a class="el" href="dir_498be2c65a0c2ce1eedf70fa7edfe8f7.html">SetAlgorithms</a></li><li class="navelem"><a class="el" href="_set_algorithms_8cs.html">SetAlgorithms.cs</a></li>
    <li class="footer">Generated on Thu Dec 26 2013 14:21:42 for SystemSharp by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
